interface State {
  aimDom: {
    style?: { [organName: string]: string };
    context?: { value: string; type: string };
    faPosition?: { top: number; left: number };
    [organName: string]: any;
  }; //目标DOM节点
  aimPath: {}[]; //目标路径
  aimAttrs: {
    context?: string;
    goto?: { type: string; value: string };
    [organName: string]: any;
  }; //目标属性
  aimBox: {} | null; //目标容器
  aimXY: {} | null; //鼠标与组件的偏移
  componentList: { [organName: string]: {} };
  seniorBoxList: {};
  //为了可以显示margin...
  colorDomStyle: {
    width: string;
    height: string;
    top: string;
    left: string;
    padding: string;
    border: string;
    margin: string;
  };
  judgeColorDom: boolean;
  domStack: {}[]; //存储栈
  domStackNum: number; //存储栈控制下标
  page?: {
    tree: {
      [organName: string]: {}[];
    };
  };
}

export default function controlColBoxDialog(
  state: State,
  {
    that,
  }: {
    that: {
      colBoxWidth: number[];
      pageName: string;
    };
  }
) {
  let colBox = JSON.parse(JSON.stringify(state.componentList["colBox"]));

  colBox.attrs.class = `colBox${new Date().getTime()}`;
  that.colBoxWidth.forEach((item, index) => {
    colBox.children.push({
      attrs: {
        class: "colBoxItem" + index,
        "data-type": "colBoxItem",
      },
      style: {
        padding: "10px 10px 10px 10px",
        width: item + "%",
      },
      children: [],
      tagName: "div",
    });
  });

  state.domStackNum += 1;
  state.domStack.splice(state.domStackNum);
  state.domStack.push({
    type: "add",
    pageName: that.pageName,
    data: [colBox, state.page?.tree[that.pageName].length],
    path: [
      {
        className: colBox.attrs.class,
      },
    ],
  });

  state.page?.tree[that.pageName].push(colBox as {});
}
